package cn.stylefeng.guns.modular.api.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.ums.entity.ChatPreset;
import cn.stylefeng.guns.modular.ums.entity.RobotLog;
import cn.stylefeng.guns.modular.ums.model.params.ChatPresetParam;
import cn.stylefeng.guns.modular.ums.model.params.RobotLogParam;
import cn.stylefeng.guns.modular.ums.model.result.ChatPresetResult;
import cn.stylefeng.guns.modular.ums.service.ChatPresetService;
import cn.stylefeng.guns.modular.ums.service.RobotLogService;
import cn.stylefeng.guns.modular.wms.model.params.ApplyLogParam;
import cn.stylefeng.guns.modular.wms.model.params.ApplyReadParam;
import cn.stylefeng.guns.modular.wms.model.result.ApplyLogResult;
import cn.stylefeng.guns.modular.wms.service.ApplyLogService;
import cn.stylefeng.guns.modular.wms.service.ApplyReadService;
import cn.stylefeng.guns.utils.MemberTokenUtil;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *智能客服
 */
@Controller
@RequestMapping("/api/chat")
@Api(tags = "智能客服管理")
public class ApiChatController extends BaseController {

    @Autowired
    private ChatPresetService chatPresetService;
    @Autowired
    private RobotLogService robotLogService;

    /**
     * 查询常见问题列表
     */
    @ResponseBody
    @RequestMapping(value = "/getChatAskList",method = RequestMethod.GET)
    @ApiOperation(value = "查询常见问题列表", notes = "查询常见问题列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getChatAskList(ChatPresetParam param) {
        LayuiPageInfo pageInfo= chatPresetService.findPageBySpec(param);
        return ResponseData.success(pageInfo);
    }

    /**
     * 查询回复信息
     */
    @ResponseBody
    @RequestMapping(value = "/getChatReply",method = RequestMethod.GET)
    @ApiOperation(value = "查询回复信息", notes = "查询回复信息")
    public ResponseData getChatReply(ChatPresetParam param) {
        ChatPresetResult result=chatPresetService.findBySpec(param);
        return ResponseData.success(result);
    }


    /**
     *  添加智能聊天记录
     */
    @ResponseBody
    @RequestMapping(value = "/addRobotLog",method = RequestMethod.POST)
    @ApiOperation(value = "添加智能聊天记录", notes = "添加智能聊天记录")
    public ResponseData addRobotLog(@RequestBody RobotLogParam param) {
        try {
            int memberId=MemberTokenUtil.getMemberId();
            param.setMemberId(memberId);
            robotLogService.add(param);
            return ResponseData.success();
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

    /**
     * 查询智能聊天记录
     */
    @ResponseBody
    @RequestMapping(value = "/getRobotLogList",method = RequestMethod.GET)
    @ApiOperation(value = "查询智能聊天记录", notes = "查询智能聊天记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "limit", value = "每页数量", dataType = "Integer", paramType = "query")
    })
    public ResponseData getRobotLogList(RobotLogParam param) {
        try {
            int memberId=MemberTokenUtil.getMemberId();
            param.setMemberId(memberId);
            LayuiPageInfo pageInfo= robotLogService.findPageBySpec(param);
            return ResponseData.success(pageInfo);
        }catch (Exception e){
            return ResponseData.error(e.getMessage());
        }
    }

}



